pp108 : Using Logging Framework

Using Logging Framework

This topic describes how the logging framework is used.


A developer can use the logging framework by inserting log messages of the required severity in the existing source code (shown in the example below) , and executing it when the option to log is enabled. Log statements are published to selected consumers (also known as publishers or appenders), based on the option selected during configuration.
See the following example for logging a string message.

import com.eibus.soap.ApplicationTransaction;
import com.eibus.soap.BodyBlock;
import com.eibus.util.logger.CordysLogger;
import com.eibus.util.logger.Severity;
import com.eibus.xml.nom.Node;
public class Transaction 
implements ApplicationTransaction
{
static CordysLogger srLogger =
CordysLogger.getCordysLogger(Transaction.class);
//getCordysLogger Web service operation takes the same class as the argument
public void commit()
{
}
public void abort()
{
}
public boolean canProcess(String type)
{
return 'serviceType'.equals(type);
}
public boolean process(BodyBlock requestBodyBlock, BodyBlock
responseBodyBlock)
{
boolean invoked =false;
try
{
int response = responseBodyBlock.getXMLNode();
int request = requestBodyBlock.getXMLNode();
if (srLogger.isInfoEnabled())
srLogger.log(Severity.INFO,'Request received ..\n'
+Node.writeToString(request,true));
//
// implementation here
//
if (srLogger.isInfoEnabled())
srLogger.log(Severity.INFO,'Response from the Service is ..\n'
+Node.writeToString(response,true));
}
catch(Exception ex)
{
srLogger.log(Severity.ERROR,'exception',ex);
}
return invoked;
}
}

For more information on other methods, please see the SDK
Logging IStringResource
The class containing log messages (IStringResource) has to be created before using this API. Messages can be logged using the ID of the message.

The MessageID returns com.eibus.localization.message.Message object . This is an implementation of the IStringResource .

Please see Generating Log Messages for creating the IStringResource.
Example:

import com.eibus.localization.message.internal.LogMessages;
import com.eibus.soap.ApplicationTransaction;
import com.eibus.soap.BodyBlock;
import com.eibus.util.logger.CordysLogger;
import com.eibus.util.logger.Severity;
import com.eibus.xml.nom.Node;
public class Transaction 
implements ApplicationTransaction
{
static CordysLogger srLogger =
CordysLogger.getCordysLogger(Transaction.class);
//getCordysLogger Web service operation takes the same class as the argument
public void commit()
{
}
public void abort()
{
}
public boolean canProcess(String type)
{
return 'serviceType'.equals(type);
}
public boolean process(BodyBlock requestBodyBlock, BodyBlock
responseBodyBlock)
{
boolean invoked =false;
try
{
if (srLogger.isInfoEnabled()) 
srLogger.info(LogMessages.METHOD_INVOKED);
//
// Method Implementation here
//
//
}
catch(Exception ex)
{
srLogger.error(ex,LogMessages.METHOD_INVOKE_ERROR); 
}
return invoked;
}
}


Note: LogMessages. METHOD_INVOKED & LogMessages. METHOD_INVOKE_ERROR returns the Message objects (Implementation of IStringResource) corresponding to the ID. For more information on other methods, please refer to SDK.
How Messages Are Logged

Messages are logged to the selected consumer with the class name asCategory. Please refer Log Consumers for more information on this.